#ifndef WIDGET_H
#define WIDGET_H

#include <QOpenGLWidget>
#include <QOpenGLExtraFunctions>
//#include <QOpenGLShaderProgram>
#include <QDebug>
#include <QOpenGLTexture>
#include <QMatrix>
#include <QVector4D>
#include <QTimer>
#include <QKeyEvent>
#include <QCursor>
#include "lightshader.h"
#include "cubeshader.h"

class Widget : public QOpenGLWidget, protected QOpenGLExtraFunctions
{
    Q_OBJECT
public:
    Widget(QOpenGLWidget* parent = nullptr);
    ~Widget();

protected:
    virtual void initializeGL();
    virtual void resizeGL(int w, int h);
    virtual void paintGL();
    void keyPressEvent(QKeyEvent *event);
    void mousePressEvent(QMouseEvent *event);
    void mouseMoveEvent(QMouseEvent *event);
    void wheelEvent(QWheelEvent *event);

public slots:
    void timeout();

private:
    LightShader* lightShader;
    CubeShader* cubeShader;
    //着色器程序
    QOpenGLShaderProgram* m_program;
    //位置
    GLuint m_posAttr;
    GLuint m_colorAttr;
    GLuint m_texCoordAttr;
    GLuint m_normalAttr;

    GLuint m_VAO[1];
    GLuint m_VBO[1];
    GLuint m_EBO[1];
    GLuint m_texture;

    QOpenGLTexture *m_textureBg;

    GLuint m_projection;
    GLuint m_view;
    GLuint m_model;

    GLfloat m_angle;
    QTimer* m_timer;

    int firstMouse;
    QCursor m_cursor;

    GLuint m_lightPos;
    GLuint m_objectColor;
    GLuint m_lightColor;

    // light
    GLuint m_VAO_Light[1];
    QOpenGLShaderProgram* m_program_light;
    GLuint m_lightPosAttr;
    GLuint m_lightColor2;

};

#endif // WIDGET_H
